package com.five.dao.impl.reception;

import com.five.dao.reception.OrderDao;
import com.five.entity.backstage.TStaff;
import com.five.entity.reception.Order;
import com.five.util.DBUtil;
import com.five.util.Page;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @Author: 王登峰
 * @Description:
 * @Date: 2020/11/27 16:41
 */
@Repository
public class OrderDaoImpl implements OrderDao {
    @Override
    public void getDate(Order order) {
        String sql="{call create_calendar('"+order.getRzdate()+"','"+order.getLeavedate()+"')}";
        DBUtil.getCall(sql);
    }
    @Override
    public int addOrder(Order order) {
        String sql = "insert into t_order(createtime,orderid,price,uid,name,tel,roomtype,count,rzdate,leavedate) " +
                "values(now(),?,?,?,?,?,?,?,?,?)";
        return DBUtil.manage(sql,order.getOrderid(),order.getPrice(),order.getUid(),order.getName(),order.getTel(),order.getRoomtype(),order.getCount(),
                order.getRzdate(),order.getLeavedate());
    }
    @Override
    public List<Map> selectOder(Page page, Order order){
        StringBuffer sql = new StringBuffer("select a.*,b.name tname,b.money,b.yj from t_order a left join t_type b on a.roomtype=b.id where 1=1");
        if(order.getOrderid()!= null && order.getOrderid()!= ""){
            sql.append(" and orderid like '%"+order.getOrderid()+"%'");
        }
        if(order.getName()!= null && order.getName()!= ""){
            sql.append(" and a.name like '%"+order.getName()+"%'");
        }
        sql.append(" order by id limit ?,?");
        String s = sql.toString();
        int pagesize = page.getLimit();
        int star = (page.getPage()-1)*pagesize;
        return DBUtil.queryMap(s,star,pagesize);
    }

    @Override
    public int count(Order order) {
        StringBuffer sql = new StringBuffer("select count(*) a from t_order where 1=1");
        if(order.getOrderid()!= null && order.getOrderid()!= ""){
            sql.append(" and orderid like '%"+order.getOrderid()+"%'");
        }
        if(order.getName()!= null && order.getName()!= ""){
            sql.append(" and name like '%"+order.getName()+"%'");
        }
        String s = sql.toString();
        List<Map> list = DBUtil.queryMap(s);
        String a = list.get(0).get("a") + "";
        int i = Integer.parseInt(a);
        return i;
    }
}
